<template>
  <div class="container">
    <div class="left-panel">
      <div class="fieldBox">
        <div class="header">
          <span class="name">字段列表</span>
        </div>
        <div class="list">
          <div role="group" aria-label="checkbox-group" class="el-checkbox-group">
            <label v-for="field in fields" :key="field.value" class="el-checkbox">
              <span class="el-checkbox__input">
                <span class="el-checkbox__inner"></span>
                <input type="checkbox" v-model="selectedFields" :value="field.value" class="el-checkbox__original" />
              </span>
              <span class="el-checkbox__label">{{ field.label }}</span>
            </label>
          </div>
        </div>
      </div>
    </div>

    <div class="right-panel">
      <div class="setting">
        <div class="item">
          <div class="label">编码位置</div>
          <div role="radiogroup" class="el-radio-group radioGroup">
            <label class="el-radio" v-for="option in positionOptions" :key="option.value">
              <span class="el-radio__input">
                <span class="el-radio__inner"></span>
                <input type="radio" v-model="selectedPosition" :value="option.value" class="el-radio__original" />
              </span>
              <span class="el-radio__label">{{ option.label }}</span>
            </label>
          </div>
        </div>
        <div class="item">
          <div class="label">顶部字段</div>
          <div class="el-select el-select--small">
            <select v-model="topField" @change="onTopFieldChange">
              <option v-for="field in fields" :key="field.value" :value="field.value">{{ field.label }}</option>
            </select>
          </div>
        </div>
        <div class="item">
          <div class="label">底部字段</div>
          <div class="el-select el-select--small">
            <select v-model="bottomField" @change="onBottomFieldChange">
              <option v-for="field in fields" :key="field.value" :value="field.value">{{ field.label }}</option>
            </select>
          </div>
        </div>
      </div>

      <div class="preview">
        <div class="label">预览效果</div>
        <div class="box">
          <div class="barCode">
            <img :src="barcodeImage" class="img" />
          </div>
          <div class="content">
            <div class="row">
              <span class="name">资产名称</span>
              <span class="value">{{ selectedAssetName }}</span>
            </div>
            <div class="row">
              <span class="name">顶部字段</span>
              <span class="value">{{ topField }}</span>
            </div>
            <div class="row">
              <span class="name">底部字段</span>
              <span class="value">{{ bottomField }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue';

export default {
  setup() {
    const fields = ref([
      { label: '公司名称', value: 'ownDeptName' },
      { label: '资产名称', value: 'assetName' },
      { label: '资产分类', value: 'categoryName' },
      { label: '品牌', value: 'assetBrand' },
      { label: '型号', value: 'specType' },
      { label: '购置时间', value: 'buyDate' },
      { label: '购置金额', value: 'includeTaxPrice' },
      { label: '管理员', value: 'managerName' },
      { label: '所在位置', value: 'locationName' },
      { label: '使用人', value: 'useByName' },
      { label: '使用部门', value: 'useDeptName' },
      { label: '供应商', value: 'supplierName' },
    ]);

    const selectedFields = ref([]);
    const selectedPosition = ref('left');
    const topField = ref('');
    const bottomField = ref('');
    const barcodeImage = ref('')
    const positionOptions = ref([
      { label: '左', value: 'left' },
      { label: '右', value: 'right' },
    ]);

    const selectedAssetName = ref(''); // 这里可以根据选择的字段动态更新

    const onTopFieldChange = () => {
      console.log('选中的顶部字段:', topField.value);
    };

    const onBottomFieldChange = () => {
      console.log('选中的底部字段:', bottomField.value);
    };

    return {
      fields,
      selectedFields,
      selectedPosition,
      topField,
      bottomField,
      barcodeImage,
      positionOptions,
      selectedAssetName,
      onTopFieldChange,
      onBottomFieldChange,
    };
  },
};
</script>

<style scoped>
.container {
  width: 1200px;
  display: flex;
  justify-content: space-between;
  padding: 20px;
  background-color: #f9f9f9;
  border-radius: 8px;
}

.left-panel {
  flex: 1;
  margin-right: 20px;
}

.right-panel {
  flex: 1;
}

.fieldBox {
  padding: 15px;
  background-color: #ffffff;
  border: 1px solid #e4e7ed;
  border-radius: 8px;
}

.header {
  margin-bottom: 10px;
}

.name {
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.list {
  margin-bottom: 20px;
}

.el-checkbox-group {
  display: flex;
  flex-direction: column;
}

.el-checkbox {
  margin-bottom: 10px;
}

.setting {
  margin-bottom: 20px;
}

.item {
  margin-bottom: 16px;
}

.label {
  font-weight: 500;
  margin-bottom: 8px;
  color: #555;
}

.el-select {
  width: 100%;
}

.preview {
  margin-top: 20px;
  border-top: 1px solid #e4e7ed;
  padding-top: 10px;
}

.box {
  display: flex;
  align-items: center;
  border: 1px solid #e4e7ed;
  padding: 10px;
  border-radius: 4px;
  margin-top: 10px;
  background-color: #ffffff;
}

.barCode {
  width: 90px;
  height: 90px;
}

.img {
  max-width: 100%;
  height: auto;
}

.content {
  display: flex;
  flex-direction: column;
  margin-left: 10px;
  flex-grow: 1;
}

.row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.value {
  color: #666;
  font-weight: 500;
}
</style>